home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -screenplay- / shareware / scott / source / source.lha / AMIGA6.C next >
C/C++ Source or Header  |  1999-04-04  |  45KB  |  1,672 lines

  1. /*
  2.  *  AMIGA Libs & Functions for Scott-Free
  3.  *
  4.  *  ===================================================================
  5.  *
  6.  *  Version History AMIGA:
  7.  *  Ver ,     Date,     Author, Comment
  8.  *  -------------------------------------------------------------------
  9.  *  1.0 , 28/07/96, Andreas Aumayr, First public release
  10.  *  1.1 , 16/08/96, Andreas Aumayr, Added ToolType support & font prefs
  11.  *  1.2 , 30/08/96, Andreas Aumayr, ASL-FR for Load/Save/Datafile
  12.  *  1.3 , 08/09/96, Andreas Aumayr, Menus, loads of minor enhancements,
  13.  *                                  'real' command history, more TTs
  14.  *  1.4 , 17/09/96, Andreas Aumayr, Public screen support, more TTs, ..
  15.  *  1.5 and higher: Andreas Aumayr, just to lazy to keep track of changes :-)
  16.  *  ___________________________________________________________________
  17.  */
  18.  
  19. #define  MAX_HIST 20
  20. #define  MAX_LL   40
  21. #define  PIC       8
  22. #define  COC       7
  23. #define  OVL       6
  24. #define  ANI       5
  25. #define  GOT       4
  26.  
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <stdlib.h>
  30. #include <ctype.h>
  31. #include <stdarg.h>
  32. #include <time.h>
  33.  
  34. #include <exec/memory.h>
  35. #include <intuition/intuition.h>
  36. #include <graphics/GfxBase.h>
  37. #include <graphics/rpattr.h>
  38. #include <workbench/workbench.h>
  39. #include <libraries/dos.h>
  40. #include <libraries/dosextens.h>
  41. #include <dos/exall.h>
  42. #include <utility/tagitem.h>
  43. #include <libraries/asl.h>
  44. #include <libraries/gadtools.h>
  45. #include <workbench/startup.h>
  46. #include <libraries/amigaguide.h>
  47. #include <datatypes/pictureclass.h>
  48. #include <devices/inputevent.h>
  49. #include <exec/types.h>
  50. #include <exec/exec.h>
  51. #include <devices/narrator.h>
  52. #include <libraries/translator.h>
  53. #include "gui.c"
  54.  
  55. extern struct MsgPort *CreatePort();
  56. extern struct IORequest *CreateExtIO();
  57. ULONG  TranslatorBase;
  58. struct MsgPort *narratorPort;
  59. struct narrator_rb *request;
  60. STRPTR nartrans[1024];
  61. ULONG  narBuf;
  62. BYTE   channels[4] = {3,5,10,12};
  63. struct IntuitionBase *IntuitionBase;
  64. struct GfxBase *GfxBase;
  65. ULONG  DiskfontBase;
  66. ULONG  IconBase;
  67. ULONG  Dos_Base;
  68. ULONG  UtilityBase;
  69. ULONG  AslBase;
  70. ULONG  GadToolsBase;
  71. ULONG  AmigaGuideBase;
  72. ULONG  DataTypesBase;
  73. struct Screen *WBscreen = NULL;
  74. struct Screen *ScottScreen = NULL;
  75. ULONG  old_pubmode;
  76. struct Window *act_w_hdl;
  77. struct Window *pic_w_hdl = NULL;
  78. APTR   WBvisinfo = NULL;
  79. struct TextFont *textfont = NULL;
  80. char   save_game[32] = "";
  81. char   data_file[32] = "",data_dir[256] = "";
  82. char   save_dir[256] = "";
  83. char   gfx_file[256] = "";
  84. char   FFP[256];
  85.  
  86. char   hist[MAX_HIST][MAX_LL+1];
  87. int    hist_pos=0,hist_fill=0;
  88.  
  89. struct Menu *menu = NULL;
  90. char   Version[] = "$VER: AMIGA SCOTT-Free V1.8, 1996-99";
  91. char   GameInfoStr[256] = "";
  92.  
  93. struct WBStartup *WBMessage;
  94. struct MsgPort *OldUserPort;
  95. BOOL   WBSTART  = FALSE;
  96. BOOL   RESTART  = TRUE;
  97. BOOL   LINEWRAP = TRUE;
  98. BOOL   GFX      = TRUE;
  99. BOOL   SPEECH   = FALSE;
  100. ULONG  Disp_ID;
  101. BOOL   FASTCOLOURS = FALSE;
  102. //BOOL   NOGFXPOS = FALSE;
  103. //BOOL   INIT = FALSE;
  104. //BOOL   GFXDOUBLE = FALSE;
  105. char   restart_file[42] = "RAM:";
  106. BPTR   restart_lock;
  107.  
  108. struct NewAmigaGuide scott_guide = {NULL};
  109. int    last_pic = -128;
  110. room_pics *rp = 0;
  111. ULONG  *go = 0;
  112. LONG   Pens[16] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
  113. UBYTE  NumColours = 0;
  114. UBYTE  planesN = 0;
  115. struct ColorRegister CR[16];
  116. struct BitMap bitmapN;
  117. int    gfx_width = 0,gfx_height = 0;
  118. WORD   win_pos_ver,win_pos_hor;
  119. int    win_width = -1,win_height;
  120. BYTE   ScreenAspect;
  121. UBYTE  *picture = 0,*rle_dat = 0,*overlay = 0;
  122. WORD   w_top;
  123. int    nroom;
  124.  
  125. FILE   *gfx_in_file;
  126.  
  127. /// NoSpeech
  128. void NoSpeech(BYTE status)
  129. {
  130.     switch(status) {
  131.         case 0:
  132.             CloseDevice(request);
  133.         case 1:
  134.             DeleteExtIO(request);
  135.         case 2:
  136.             DeletePort(narratorPort);
  137.         case 3:
  138.             CloseLibrary(TranslatorBase);
  139.             TranslatorBase = 0;
  140.             SPEECH = FALSE;
  141.     }
  142. }///
  143.  
  144. /// close_libs
  145. void close_libs(void)
  146. {
  147.         if (TranslatorBase) NoSpeech(0);
  148.         if (AmigaGuideBase) CloseLibrary(AmigaGuideBase);
  149.         if (GadToolsBase) CloseLibrary(GadToolsBase);
  150.         if (AslBase) CloseLibrary(AslBase);
  151.         if (UtilityBase) CloseLibrary(UtilityBase);
  152.         if (Dos_Base) CloseLibrary(Dos_Base);
  153.         if (IconBase) CloseLibrary(IconBase);
  154.         if (DiskfontBase) CloseLibrary(DiskfontBase);
  155.         if (GfxBase) CloseLibrary(GfxBase);
  156.         if (IntuitionBase) CloseLibrary(IntuitionBase);
  157. }///
  158.  
  159. /// open_libs
  160. BOOL open_libs(void)
  161. {
  162.                 IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",37);
  163.                 if (IntuitionBase == NULL) {
  164.                         printf("Problems opening Intuition-Lib!\n");
  165.                         return(FALSE);
  166.                 }
  167.                 GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",37);
  168.                 if (GfxBase == NULL) {
  169.                         printf("Problems opening GFX-Lib!\n");
  170.                         return(FALSE);
  171.                 }
  172.                 DiskfontBase = OpenLibrary("diskfont.library",0);
  173.                 if (DiskfontBase == 0) {
  174.                         EasyRequest(NULL,&Library,NULL,"DiskFont");
  175.                         return(FALSE);
  176.                 }
  177.                 IconBase = OpenLibrary("icon.library",0);
  178.                 if (IconBase == 0) {
  179.                         printf("Problems opening Icon-Lib!\n");
  180.                         return(FALSE);
  181.                 }
  182.                 Dos_Base = OpenLibrary("dos.library",0);
  183.                 if (Dos_Base == 0) {
  184.                         printf("Problems opening DOS-Lib!\n");
  185.                         return(FALSE);
  186.                 }
  187.                 UtilityBase = OpenLibrary("utility.library",0);
  188.                 if (UtilityBase == 0) {
  189.                         printf("Problems opening Utility-Lib!\n");
  190.                         return(FALSE);
  191.                 }
  192.                 AslBase = OpenLibrary("asl.library",0);
  193.                 if (AslBase == 0) {
  194.                         EasyRequest(NULL,&Library,NULL,"ASL");
  195.                         return(FALSE);
  196.                 }
  197.                 GadToolsBase = OpenLibrary("gadtools.library",36);
  198.                 if (GadToolsBase == 0) {
  199.                         printf("Problems opening GadTools-Lib!\n");
  200.                         return(FALSE);
  201.                 }
  202.                 AmigaGuideBase = OpenLibrary("amigaguide.library",0);
  203.                 TranslatorBase = OpenLibrary("translator.library",0);
  204.                 if (TranslatorBase) {
  205.                     narratorPort = (struct MsgPort *) CreatePort(0,0);
  206.                     if (narratorPort == NULL) NoSpeech(3);
  207.                     else {
  208.                         request = (struct narrator_rb *) CreateExtIO(narratorPort, sizeof(struct narrator_rb));
  209.                         if (request == NULL) NoSpeech(2);
  210.                         else if (OpenDevice("narrator.device",0,request,0)) NoSpeech(1);
  211.                     }
  212.                 }
  213.                 return(TRUE);
  214. }///
  215.  
  216. ///FreeGFXRes
  217. void FreeGFXRes(void)
  218. {
  219.     int     i;
  220.  
  221.     if (gfx_in_file) fclose(gfx_in_file);
  222.     
  223.     if (rp) free(rp);
  224.     if (go) free(go);
  225.  
  226.     if (FASTCOLOURS) for (i=0;i<NumColours;i++) SetRGB4(&WBscreen->ViewPort,i,(Pens[i]&0x0F00)>>8,(Pens[i]&0x00F0)>>4,Pens[i]&0x000F);
  227.     else {
  228.         for (i=0; i<NumColours; i++) {
  229.             if (Pens[i] > 0) ReleasePen(WBscreen->ViewPort.ColorMap,Pens[i]);
  230.             else break;
  231.         }
  232.     }
  233.  
  234.     for (i=0; i<planesN; i++) {
  235.         if (bitmapN.Planes[i]) FreeRaster(bitmapN.Planes[i],gfx_width,gfx_height);
  236.         else break;
  237.     }
  238.  
  239.     if (picture) FreeMem(picture,gfx_width*gfx_height);
  240.     if (rle_dat) FreeMem(rle_dat,gfx_width*gfx_height);
  241.     if (overlay) FreeMem(overlay,gfx_width*gfx_height);
  242. }///
  243.  
  244. /// close_all
  245. void close_all(void)
  246. {
  247.     if (restart_lock) UnLock(restart_lock);
  248.     DeleteFile(restart_file);
  249.  
  250.     if (menu) FreeMenus(menu);
  251.     if (WBvisinfo) FreeVisualInfo(WBvisinfo);
  252.     if (WBscreen) UnlockPubScreen(NULL,WBscreen);
  253.     if (textfont) CloseFont(textfont);
  254.     if (pic_w_hdl) CloseWindow(pic_w_hdl);
  255.     if (act_hdl) {
  256.         act_w_hdl->UserPort = OldUserPort;
  257.         Close(act_hdl);
  258.     }
  259.     if (env_hdl) Close(env_hdl);
  260.  
  261.     if (GFX) FreeGFXRes();
  262.  
  263.     SetPubScreenModes(old_pubmode);
  264.     if (ScottScreen) {
  265.         while (CloseScreen(ScottScreen) == FALSE) EasyRequest(NULL,&ClosePub,NULL,NULL);
  266.     }
  267.     close_libs();
  268. }///
  269.  
  270. /// MemAlloc
  271. void * MemAlloc(int size)
  272. {
  273.     void *t = (void *) AllocMem(size,MEMF_ANY|MEMF_CLEAR);
  274.     if (t == NULL) {
  275.         printf("\nUnable to get some mem!\nTerminating.\n");
  276.         EasyRequest(NULL,&NoMem,NULL,NULL);
  277.         close_all();
  278.         exit(128);
  279.     }
  280.     return(t);
  281. }///
  282.  
  283. /// Open_CON
  284. struct FileHandle *Open_CON(char *type, int left_off, int top_off, int width, int height, char *title, char *flags, char *cscreen)
  285. {
  286.     sprintf(str_buf,"%s:%d/%d/%d/%d/%s/%s/SCREEN %s",type,left_off,top_off,width,height,title,flags,cscreen);
  287.     CON_handle = (struct FileHandle *) Open(str_buf,MODE_NEWFILE);
  288.     if (!CON_handle) {
  289.         printf("Failed to open console window '%s'!\n",title);
  290.         EasyRequest(NULL,&ConFail,NULL,title);
  291.         close_all();
  292.         exit(99);
  293.     }
  294.     else return(CON_handle);
  295. }///
  296.  
  297. ///dyn_strings
  298. void * dyn_strings(char *cont, BYTE add)
  299. {
  300.         void *mem_ptr;
  301.  
  302.         if (cont && strlen(cont)) {
  303.                 mem_ptr = Mem